<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/js/jquery-2.1.1.min.js"></script>
    <script src="/js/my97/WdatePicker.js"></script>
    <link rel="stylesheet"  href="/js/uploadify/uploadify.css" />
    <script src="/js/uploadify/jquery.uploadify.min.js"></script>
    <link rel="stylesheet" href="/js/kindeditor-4.1.10/themes/default/default.css" />
    <script src="/js/kindeditor-4.1.10/kindeditor-all.js"></script>
    <link rel="stylesheet" href="/js/easyui1.5/themes/default/easyui.css" type="text/css"></link>
    <link rel="stylesheet" href="/js/easyui1.5/themes/icon.css" type="text/css"></link>
    <script type="text/javascript" src="/js/easyui1.5/jquery.easyui.min.js"></script>
    <script src="/layer/layer.js"></script>


</head>
<body>
<input type="hidden" th:value="${msg}" id="mg">
<ul id="tree"></ul>
<a id="btn" href="javascript:void(0)" onclick="addPowerToRole()" class="easyui-linkbutton" data-options="iconCls:'icon-add'">
    增加权限
</a>
</body>
<script type="text/javascript" th:inline="none">
    $(function(){
        loadTree();
    })

    var id=$("#mg").val();

    function loadTree(){

        $('#tree').tree({
            url:'/role/queryTreeByRoleid?roleid='+id,
            checkbox:true,
            lines:true
        });
    }
    function addPowerToRole(){
        //获取选中的和不确定的
        var nodes = $('#tree').tree('getChecked', ['checked','indeterminate']);

        console.log(nodes)

        var param = {roleid:id}

        $.each(nodes,function(index,obj){//权限的id

            param["powerId["+index+"]"] = obj.id;
        })

        $.ajax({
            url:"/role/addPowerToRole",
            type:"POST",
            data:param,//加上loading框
            success:function(result){
                if(result.length>20){

                    window.location="/view/reject"
                }
                layer.msg("分配成功 50秒后生效");
            },
            error:function(){
                alert("ajax访问失败了,查看控制台");
            }
        });
    }
</script>
</html>